package com.snail.readyvr.glide;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.snail.readyvr.R;
import com.snail.readyvr.ui.RoundedImageView;

import java.io.File;

/**
 * Created by MRKING on 2016/10/12.
 * Glide 图片加载辅助类
 */

public class GlideUtils {
    private GlideUtils(){}

    /**
     * 根据url加载图片
     * @param context
     * @param url
     * @param imageView
     */
    public static void loadImgFromUrl(Context context, String url, ImageView imageView){
        Glide.with(context).load(url)
                .centerCrop()
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(imageView);
    }
    /**
     * 根据url加载图片
     * @param context
     * @param url
     * @param imageView
     */
    public static void loadImgFromUrlNoCrop(Context context, String url, ImageView imageView){
        Glide.with(context).load(url)
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .into(imageView);
    }

    /**
     * 根据file加载图片 可以加载本地图片
     * @param context
     * @param file
     * @param imageView
     */
    public static void loadImgFromFile(Context context, File file, ImageView imageView){
        Glide.with(context).load(file)
                .centerCrop()
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(imageView);
    }

    /**
     * 加载本地图片
     * @param context
     * @param fileUrl
     * @param imageView
     */
    public static void loadImgFromLocal(Context context, String fileUrl, ImageView imageView){
        File file = new File(fileUrl);
        Glide.with(context).load(file)
                .centerCrop()
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(imageView);
    }

    /**
     * 加载 drawable 图片
     * @param context
     * @param resId
     * @param imageView
     */
    public static void loadImgFromDrawable(Context context, int resId, ImageView imageView){

        Glide.with(context).load(resId)
                .centerCrop()
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(imageView);
    }

    /**
     * 加载 欢迎页面图片
     * @param context
     * @param resId
     * @param imageView
     */
    public static void loadWelcomeImgFromDrawable(Context context, int resId, ImageView imageView){

        Glide.with(context).load(resId)
                .centerCrop()
                .crossFade(2500)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .skipMemoryCache(true)
                .into(imageView);
    }

    public static void loadRoundImg(Context context, String url, RoundedImageView roundedImageView){
        Glide.with(context).load(url)
                .placeholder(R.drawable.placehold_image_2)
                .error(R.drawable.placehold_image_2)
                .animate(android.R.anim.fade_in)
                .diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .centerCrop()
                .into(roundedImageView);
    }
}
